
**************************************************************************
*******																 *****
*******	COMMON OWNERSHIP, COMPETITION, AND TOP MANAGEMENT INCENTIVES *****
*******						Journal of Political Economy			 *****
******* by: Miguel Antón, Florian Ederer, Mireia Giné, Martin Schmalz ****
*******																 *****
**************************************************************************

**************************************************************************
**																		**
** Please read the companion appendix README file available at the      **
** publisher's website, or on the authors' research page.               **
**                                                                      **
** Data:															    **
** Data used in the analysis are not sharable due to the data licensing **
** agreement between the authors (and their institutions) with the data **
** providers. Details of the used data sets are provided in the README. **
** All used data sets can be independently obtained from the data vendor**
** and are clearly documented in the README file.                       **
**																		**
** Cleaned Data Sets Referenced to In This Code:                        **
** Detailed steps used in generating those data sets are provided in the**
** README file with the same data set names. 							**
** - master_main.dta													**
** - master_did.dta														**
** - master_did_change.dta		  										**
** - master_did_additions.dta											**
**																		**
**************************************************************************



**************************************************************************
*****************               Setup               **********************
**************************************************************************

// Change to your directory.

global work [CHANGE TO YOUR WORK DIRECTORY]

clear all
cd $work

// Under the directory there is one main folder
	* data
	
**************************************************************************
***************** Table 1: Summary of Model Setup   **********************
**************************************************************************

// This Table corresponds to the Summary of the Model Setup. 

**************************************************************************
***************** Table 2: Examples Ownership Airlines *******************
**************************************************************************

// Table 2 Panel A comes from S&P Capital IQ (Q2 2016). 
// Table 2 Panel B is taken from Azar et al. (2018).

**************************************************************************
***************** Table 3: Theoretical Predictions  **********************
**************************************************************************

// This Table corresponds to the theoretical predictions and empirical evidence. 

**************************************************************************
***************** Table 4: Summary Statistics       **********************
**************************************************************************

#delimit ; 

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

* CEO Variables;
sum wpsegl_allexec wpsjm_allexec wpshl_allexec tenure, det;

* Firm Variables;
sum log_mef vol leverage, det;

* Common Ownership measures (SIC-4 CRSP);
sum vwk_sich_crsp4 vwcs_sich_crsp4 vwihhi_sich_crsp4 vw_co5sich_comp4 fcap_vwsich_comp4 hjl1_vwsich_comp4, det;

* Industry variables (HHI, and MHHID);
duplicates drop sich_crsp4 year, force;
sum hsich_crsp4 mhhid1sich_crsp4, det;

**************************************************************************
***************** Table 5: WPS as function of EW and VW CO Kappas ********
**************************************************************************

#delimit ; 
clear all;

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local filename table5;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

* DEP corresponds to the dependent variable, SIC to the industry classification,
* and CO to the measure of common ownership used
 
foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/{;
	// All 6 columns have the EGL measure as Dependent Variable
foreach SIC in sich_crsp sich_comp icode4000{;
	// Columns 1 and 2 are CRSP, 3 and 4 COMP, and 5 and 6 Hoberg-Phillips
foreach CO in ewk_ vwk_ /*ewcs_ ew_co5 fcap_ew hjl1_ew mhhid1 mhhidew1*/{;
	// Columns 1, 3 and 5 correspond to EW measures of Kappa, and 2, 4, 6 to VW

reghdfe `DEP' `CO'`SIC'4t vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

drop HHI MHHID ;
};
};
};

**************************************************************************
***************** Table 6: Alternative CO measures  **********************
**************************************************************************
#delimit ; 
clear all;

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local filename table6;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpseg_allexec{;
	// All 7 columns have the EGL measure as Dependent Variable
foreach SIC in sich_crsp{;
	// All 7 columns use CRSP as industry classification
foreach CO in vwk_ vwcs_ vw_co5 fcap_vw hjl1_vw mhhid1 mhhidew1{;
	// Each column uses a different Common Ownership Measure

reghdfe `DEP' `CO'`SIC'4t vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

drop HHI MHHID ;
};
};
};

**************************************************************************
***************** Table 7: Alternative WPS measures **********************
**************************************************************************
#delimit ; 
clear all;

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local filename table7;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpsjm_allexec logwpshl_allexec{;
	// Columns 1-3 are for JM measure, and 4-6 for HL measure of WPS. 
foreach SIC in sich_crsp{;
	// All 6 columns use CRSP as industry classification
foreach CO in vwk_ vwcs_ vw_co5{;
	// Columns 1 and 4 use VW Kappa, 2 and 5 VW Cosine Similarity, and 3 and 6 Top 5

reghdfe `DEP' `CO'`SIC'4t vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

drop HHI MHHID ;
};
};
};

**************************************************************************
***************** Table 8: All Executives           **********************
**************************************************************************
#delimit ; 
clear all;

use $work\data\master_main, clear;

// We keep observations for all executives in this table

#delimit ;
local filename table8;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/{;
	// All 7 columns have the EGL measure as Dependent Variable
foreach SIC in sich_crsp /*sich_comp icode4000*/{;
	// All 7 columns use CRSP as industry classification
foreach CO in vwk_ vwcs_ vw_co5 fcap_vw hjl1_vw mhhid1 mhhidew1{;
	// Each column uses a different Common Ownership Measure

reghdfe `DEP' `CO'`SIC'4t vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(co_per_rol fyear#`SIC'3) vce(cluster co_per_rol fyear);
	outreg2 using `Table_e', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes);
	
drop HHI CO ;
};
};
};

**************************************************************************
***************** Table 9: Diff in Diff             **********************
**************************************************************************

#delimit ; 
* For CRSP and COMP;
foreach SIC in sich_crsp sich_comp /*icode4000*/{;
	// Columns 1-2 correspond to CRSP, columns 3-4 to COMP

use $work\data\master_did`SIC'vwk_, clear;

#delimit ;
keep if ceo == 1;

local filename table9;
local VARS "1.post#1.treat 1.post";
local excel "nocons nonot excel append sd(3) sortvar("`VARS'")
		keep(1.post#1.treat 1.post)";

foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/ {;
	// All 6 columns have the EGL measure as Dependent Variable

reghdfe `DEP' 
			post##(treat c.hhib c.log_mefb c.volb c.leverageb c.log_tenureb c.total_iob) 
			
			if intck<6 & intck>-6 & year_addition>1996 & year_addition<2015,
			absorb(fyear gvkey) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		True Inclusions,n,Unique Treated Firms,n,Unique Control Firms,n,
		Firm FE,Yes,Year FE,Yes,Inclusion FE,No);

reghdfe `DEP' 
			post##(treat c.hhib c.log_mefb c.volb c.leverageb c.log_tenureb c.total_iob) 
			
			if intck<6 & intck>-6 & year_addition>1996 & year_addition<2015,
			absorb(fyear gvkey count) vce(cluster count fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		True Inclusions,n,Unique Treated Firms,n,Unique Control Firms,n,
		Firm FE,Yes,Year FE,Yes,Inclusion FE,Yes);
};
};

#delimit ; 
* Now for ICODE;
foreach SIC in /*sich_crsp sich_comp*/ icode4000{;
	// Columns 5-6 correspond to Hoberg-Phillips CRSP, columns 3-4 to COMP

use $work\data\master_did`SIC'vwk_, clear;

#delimit ;
keep if ceo == 1;
destring gvkey, replace;

local filename table9;
local VARS "1.post#1.treat 1.post";
local excel "nocons nonot excel append sd(3) sortvar("`VARS'")
		keep(	1.post#1.treat 1.post)";

foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/ {;
	// All 6 columns have the EGL measure as Dependent Variable

reghdfe `DEP' 
			post##(treat c.hhib c.log_mefb c.volb c.leverageb c.log_tenureb c.total_iob) 
			
			if intck<6 & intck>-6 & year_addition>2000 & year_addition<2015,
			absorb(fyear gvkey) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		True Inclusions,n,Unique Treated Firms,n,Unique Control Firms,n,
		Firm FE,Yes,Year FE,Yes,Inclusion FE,No);

reghdfe `DEP' 
			post##(treat c.hhib c.log_mefb c.volb c.leverageb c.log_tenureb c.total_iob) 
			
			if intck<6 & intck>-6 & year_addition>2000 & year_addition<2015,
			absorb(fyear gvkey count) vce(cluster count fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		True Inclusions,n,Unique Treated Firms,n,Unique Control Firms,n,
		Firm FE,Yes,Year FE,Yes,Inclusion FE,Yes);
	
};
};



**************************************************************************
*****************        APPENDIX TABLES            **********************
**************************************************************************




**************************************************************************
***************** Table C1: Institutional Ownership Controls *************
**************************************************************************

#delimit ;

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local filename TableC1;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/{;
	// All 7 columns have the EGL measure as Dependent Variable
foreach SIC in sich_crsp /*sich_comp icode4000*/{;
	// All 7 columns use CRSP as industry classification
foreach CO in vwk_ /*vwk_ ewcs_ ew_co5 fcap_ew hjl1_ew mhhid mhhidew*/{;
	// All 7 columns use VW Kappas as measure of Common Ownership

clonevar HHI = h`SIC'4t;
clonevar MHHID = `CO'`SIC'4t;

// Column 1
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

// Column 2
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');
		
// Column 3
reghdfe `DEP' vol log_mef leverage HHI log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

// Column 4
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure top5_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

// Column 5
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure ihhi if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

// Column 6
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure ihq if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');
		
// Column 7
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure total_io ihhi if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

drop HHI MHHID ;
};
};
};

**************************************************************************
***************** Table C2: Different Control Assumptions ****************
**************************************************************************
#delimit ;

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit;
local filename TableC2;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpseg_allexec{;
	// All 9 columns have the EGL measure as Dependent Variable
foreach SIC in sich_crsp sich_comp icode4000{;
	// Columns 1-3 are CRSP, 4-6 COMP, and 7-9 Hoberg-Phillips
foreach CO in vwlambda05_ vwlambda2_ vwlambda3_{;
	// Columns 1, 4 and 7 are for VW Kappa with lambda 0.5, cols 2, 5 and 8 for l=2
	// and columns 3, 6, and 9 for l=3

clonevar HHI = h`SIC'4t;
clonevar MHHID = `CO'`SIC'4t;

reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes);

drop HHI MHHID ;
};
};
};

**************************************************************************
***************** Table C3: WPS and CO with different Fixed Effects ******
**************************************************************************
#delimit ;

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local filename TableC3;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpseg_allexec{;
	// All 10 columns have the EGL measure as Dependent Variable
foreach SIC in sich_crsp /*sich_comp icode4000*/{;
	// All 10 columns use CRSP as industry classification
foreach CO in ewk_ vwk_ /*ewcs_ ew_co5 fcap_ew hjl1_ew mhhid mhhidew*/{;
	// Columns 1-5 use EW Kappas, columns 6-10 use VW Kappas

clonevar HHI = h`SIC'4t;
clonevar MHHID = `CO'`SIC'4t;

// Columns 1 and 6
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure total_io if fyear<2020,
		noabsorb vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

// Columns 2 and 7
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure total_io if fyear<2020,
		absorb(gvkey) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

// Columns 3 and 8
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure total_io if fyear<2020,
		absorb(gvkey fyear) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');
	
// Columns 4 and 9
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure total_io if fyear<2020,
		absorb(gvkey fyear `SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

// Columns 5 and 10
reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

drop HHI MHHID ;
};
};
};

**************************************************************************
***************** Table C4: Different CO Measures for COMP and HP ********
**************************************************************************

// Panel A

#delimit ; 
clear all;

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local filename TableC4a;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpseg_allexec{;
	// All 7 columns have the EGL measure as Dependent Variable
foreach SIC in sich_comp{;
	// Panel A uses COMP
foreach CO in vwk_ vwcs_ vw_co5 fcap_vw hjl1_vw mhhid1 mhhidew1{;
	// Each column uses a different Common Ownership Measure

reghdfe `DEP' `CO'`SIC'4t vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

drop HHI MHHID ;
};
};
};

// Panel B
#delimit ; 
clear all;

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local filename TableC4b;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpseg_allexec{;
	// All 7 columns have the EGL measure as Dependent Variable
foreach SIC in icode4000{;
	// Panel B uses Hoberg-Phillips
foreach CO in vwk_ vwcs_ vw_co5 fcap_vw hjl1_vw mhhid1 mhhidew1{;
	// Each column uses a different Common Ownership Measure

reghdfe `DEP' `CO'`SIC'4t vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

drop HHI MHHID ;
};
};
};

**************************************************************************
***************** Table C5: WPS JM and HL for COMP and Hoberg-Phillips ***
**************************************************************************

// Panel A

#delimit ; 

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local filename TableC5a;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpsjm_allexec logwpshl_allexec{;
	// Columns 1-3 are for JM measure, and 4-6 for HL measure of WPS. 
foreach SIC in sich_comp{;
	// All 6 columns use COMP as industry classification
foreach CO in vwk_ vwcs_ vw_co5{;
	// Columns 1 and 4 use VW Kappa, 2 and 5 VW Cosine Similarity, and 3 and 6 Top 5

reghdfe `DEP' `CO'`SIC'4t vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

drop HHI MHHID ;
};
};
};

// Panel B

#delimit ; 

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local filename TableC5b;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpsjm_allexec logwpshl_allexec{;
	// Columns 1-3 are for JM measure, and 4-6 for HL measure of WPS. 
foreach SIC in icode4000{;
	// All 6 columns use Hoberg-Phillips as industry classification
foreach CO in vwk_ vwcs_ vw_co5{;
	// Columns 1 and 4 use VW Kappa, 2 and 5 VW Cosine Similarity, and 3 and 6 Top 5

reghdfe `DEP' `CO'`SIC'4t vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Dep Var,`DEP',Industry Def,`SIC',co,`CO',
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes,Data,`DATA');

drop HHI MHHID ;
};
};
};

**************************************************************************
***************** Table C6: Horserace Components    **********************
**************************************************************************

#delimit ; 

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local filename TableC6;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) nocons nonot excel append";

foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/ {;
foreach SIC in sich_crsp /*sich_comp icode4000*/{;

clonevar HHI = h`SIC'4;

reghdfe `DEP' vwk_`SIC'4t vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes);

reghdfe `DEP' vwlogk_`SIC'4 vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes);

reghdfe `DEP' vwlogcs_`SIC'4 vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes);

reghdfe `DEP' vwlogihhi_`SIC'4 vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes);

reghdfe `DEP' vwlogcs_`SIC'4 vwlogihhi_`SIC'4 vol log_mef leverage h`SIC'4t log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes);

drop HHI;
};
};

**************************************************************************
***************** Table C7: Lagged CO Measures      **********************
**************************************************************************

#delimit ; 

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

#delimit ;
local VARS "MHHID";
local filename TableC7;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) 
	nocons nonot excel append sortvar("`VARS'")";

foreach DEP in logwpseg_allexec{;
foreach SIC in sich_crsp sich_comp icode4000{;
foreach CO in vwk_ vwcs_ vw_co5{;

clonevar HHI = h`SIC'4t;
clonevar MHHID = `CO'`SIC'4t;

reghdfe `DEP' l.MHHID vol log_mef leverage HHI log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'3) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Firm FE,Yes,Industry SIC-3 x Year FE,Yes);

drop HHI MHHID ;
};
};
};

**************************************************************************
***************** Table C8: Coarser Industry Definitions *****************
**************************************************************************

#delimit ; 

use $work\data\master_main, clear;

// We only keep observations for CEOs in this table
keep if ceo == 1;

local VARS "MHHID HHI logsale ";
local filename TableC8;
local excel "drop(_I* o.* yeardum* sich_crsp2dum*) sd(3) 
	nocons nonot excel append sortvar("`VARS'")";

foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/{;
foreach SIC in sich_crsp sich_comp icode3000{;
foreach CO in vwk_ vwcs_ vw_co5 {;

clonevar HHI = h`SIC'3t;
clonevar MHHID = `CO'`SIC'3t;

reghdfe `DEP' MHHID vol log_mef leverage HHI log_tenure total_io if fyear<2020,
		absorb(gvkey fyear#`SIC'2) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(
		Firm FE,Yes,Industry SIC-2 x Year FE,Yes);
	
drop HHI MHHID ;
};
};
};

**************************************************************************
***************** Table C9: Shock DiD for WPS JM and HL  *****************
**************************************************************************

#delimit ; 
* For CRSP and COMP;
foreach SIC in sich_crsp sich_comp /*icode4000*/{;
foreach CO in vwk_{;

clear; clear mata; clear matrix;

use $work\data\master_did`SIC'`CO', clear;

#delimit ;
keep if ceo == 1;
destring gvkey, replace;

set more off; 
local VARS "1.post#1.treat 1.post";
local filename TableC9;
local excel "nocons nonot excel append sd(3) sortvar("`VARS'")
		keep(1.post#1.treat 1.post)";

foreach DEP in /*logwpseg_allexec*/ logwpsjm_allexec logwpshl_allexec {;

reghdfe `DEP' 
			post##(treat c.hhib c.log_mefb c.volb c.leverageb c.log_tenureb c.total_iob) 
			
			if intck<6 & intck>-6 & year_addition>1996 & year_addition<2015,
			absorb(fyear gvkey) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		True Inclusions,n,Unique Treated Firms,n,Unique Control Firms,n,
		Firm FE,Yes,Year FE,Yes,Inclusion FE,No);

reghdfe `DEP' 
			post##(treat c.hhib c.log_mefb c.volb c.leverageb c.log_tenureb c.total_iob) 
			
			if intck<6 & intck>-6 & year_addition>1996 & year_addition<2015,
			absorb(fyear gvkey count) vce(cluster count fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		True Inclusions,n,Unique Treated Firms,n,Unique Control Firms,n,
		Firm FE,Yes,Year FE,Yes,Inclusion FE,Yes);

};
};
};


#delimit ; 
* Now for ICODE;
foreach SIC in /*sich_crsp sich_comp*/ icode4000{;
foreach CO in vwk_{;

clear; clear mata; clear matrix;

use $work\data\master_did`SIC'`CO', clear;

#delimit ;
keep if ceo == 1;

set more off; 
local VARS "1.post#1.treat 1.post";
local filename TableC9;
local excel "nocons nonot excel append sd(3) sortvar("`VARS'")
		keep(	1.post#1.treat 1.post)";

foreach DEP in /*logwpseg_allexec*/ logwpsjm_allexec logwpshl_allexec {;
reghdfe `DEP' 
			post##(treat c.hhib c.log_mefb c.volb c.leverageb c.log_tenureb c.total_iob) 
			
			if intck<6 & intck>-6 & year_addition>2000 & year_addition<2015,
			absorb(fyear gvkey) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		True Inclusions,n,Unique Treated Firms,n,Unique Control Firms,n,
		Firm FE,Yes,Year FE,Yes,Inclusion FE,No);

reghdfe `DEP' 
			post##(treat c.hhib c.log_mefb c.volb c.leverageb c.log_tenureb c.total_iob) 
			
			if intck<6 & intck>-6 & year_addition>2000 & year_addition<2015,
			absorb(fyear gvkey count) vce(cluster count fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		True Inclusions,n,Unique Treated Firms,n,Unique Control Firms,n,
		Firm FE,Yes,Year FE,Yes,Inclusion FE,Yes);
	
};
};
};

**************************************************************************
***************** Table C10: Change in CO following index addition *******
**************************************************************************

#delimit ; 

foreach CO in vwk_ vwcs_{;
foreach SIC in sich_crsp sich_comp icode4000{;

use $work\data\master_did_change`SIC'`CO', clear;

local VARS "MHHID";
local filename TableC10;
local excel " nocons nonot excel append sd(3)";

foreach DEP in change{;

* 0a. No FE;
reg `DEP' treat hhib log_mefb volb leverageb log_tenureb total_iob;
	outreg2 using `filename', `excel' addtext(
		Firm FE,No,Year FE,No,CO,`CO');

* 0c. Firm and Year FE;
reghdfe `DEP' treat hhib log_mefb volb leverageb log_tenureb total_iob, 
		absorb(gvkeycomp date) vce(cluster gvkeycomp);
	outreg2 using `filename', `excel' addtext(
		Firm FE,Yes,Year FE,Yes,CO,`CO');
};
};
};





*****************************************************************;
*****************************************************************;
*		 			FIGURES AND APPENDIX FIGURES				 ;
*****************************************************************;
*****************************************************************;


************************************************************;
* FIGURE 1: THEORY ; 
************************************************************;

************************************************************;
* FIGURE 2: THEORY ; 
************************************************************;

************************************************************;
* FIGURE 3: Distributions ; 
************************************************************;

///// Pay attention this piece of code is run in SAS, not in STATA

// %macro additions;
// %let sic = sich_crsp sich_comp icode4000;
// %let co = vwk_ vwcs_;

// %let sicn = SIC_CRSP SIC_COMP Hoberg_Phillips;
// %let con = Kappa Cosine;

// %do i = 1 %to 3;
// %do j = 1 %to 2;

// ODS GRAPHICS / RESET IMAGENAME = "%scan(&co,&j)%scan(&sic,&i)master_did_change";
// ODS LISTING GPATH = "&path" ; 
// proc sgplot data=%scan(&co,&j)%scan(&sic,&i)master_did_change;
//	xaxis values=(0 to 1 by 0.2) label='Common Ownership';
//	yaxis label = 'Density';
//	density co_before / type=kernel legendlabel = "Before Inclusion"; 
// 	density co_after / type=kernel legendlabel = "After Inclusion"; 
//	where treat = 1 and co_before between 0 and 1 and co_after between 0 and 1; 
//	title "%scan(&con,&j) for %scan(&sicn,&i)";
// run;

// %end;
// %end;

///// End of SAS Part



************************************************************;
* FIGURE 4: SHOCK SP INCLUSIONS - PRE AND POST TRENDS  ; 
************************************************************;

#delimit ; 

* This is for CRSP and COMP (ICODE below, because its a different sample);

foreach SIC in sich_crsp sich_comp /*icode4000*/{;

use $work\data\master_did`SIC'`CO', clear;

keep if ceo == 1;
destring gvkey, replace;

#delimit ; 
gen ym5 = 0; replace ym5 = 1 if intck == -5;
gen ym4 = 0; replace ym4 = 1 if intck == -4;
gen ym3 = 0; replace ym3 = 1 if intck == -3;
gen ym2 = 0; replace ym2 = 1 if intck == -2;
gen ym1 = 0; replace ym1 = 1 if intck == -1;
gen ym0 = 0; replace ym0 = 1 if intck == 0;
gen yp1 = 0; replace yp1 = 1 if intck == 1;
gen yp2 = 0; replace yp2 = 1 if intck == 2;
gen yp3 = 0; replace yp3 = 1 if intck == 3;
gen yp4 = 0; replace yp4 = 1 if intck == 4;
gen yp5 = 0; replace yp5 = 1 if intck == 5;

#delimit;
set more off; 
local VARS "MHHID HHI logsale ";
local filename Figure4;
local excel " nocons nonot excel append tstat
		keep(	1.treat#1.ym5 1.treat#1.ym4 1.treat#1.ym3 1.treat#1.ym2 1.treat#1.ym1 1.treat#1.ym0 
				1.treat#1.yp1 1.treat#1.yp2 1.treat#1.yp3 1.treat#1.yp4 1.treat#1.yp5)";

foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/ {;

reghdfe `DEP' 
			treat##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5) 
			c.hhib##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
			c.log_mefb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.volb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.leverageb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.log_tenureb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
			c.total_iob##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  

			if intck<6 & intck>-6 & year_addition>1995 & year_addition<2015,
			absorb(fyear gvkey) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		Firm FE,Yes,Year FE,Yes,Inclusion FE,No,Cluster,Firm and Year);
};
};

* This is for ICODE (because its a different sample);
foreach SIC in /*sich_crsp sich_comp*/ icode4000{;

use $work\data\master_did`SIC'`CO', clear;

keep if ceo == 1;
destring gvkey, replace;

#delimit ; 
gen ym5 = 0; replace ym5 = 1 if intck == -5;
gen ym4 = 0; replace ym4 = 1 if intck == -4;
gen ym3 = 0; replace ym3 = 1 if intck == -3;
gen ym2 = 0; replace ym2 = 1 if intck == -2;
gen ym1 = 0; replace ym1 = 1 if intck == -1;
gen ym0 = 0; replace ym0 = 1 if intck == 0;
gen yp1 = 0; replace yp1 = 1 if intck == 1;
gen yp2 = 0; replace yp2 = 1 if intck == 2;
gen yp3 = 0; replace yp3 = 1 if intck == 3;
gen yp4 = 0; replace yp4 = 1 if intck == 4;
gen yp5 = 0; replace yp5 = 1 if intck == 5;

#delimit;
set more off; 
local VARS "MHHID HHI logsale ";
local filename Figure4;
local excel " nocons nonot excel append tstat
		keep(	1.treat#1.ym5 1.treat#1.ym4 1.treat#1.ym3 1.treat#1.ym2 1.treat#1.ym1 1.treat#1.ym0 
				1.treat#1.yp1 1.treat#1.yp2 1.treat#1.yp3 1.treat#1.yp4 1.treat#1.yp5)";

foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/ {;

reghdfe `DEP' 
			treat##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5) 
			c.hhib##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
			c.log_mefb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.volb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.leverageb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.log_tenureb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
			c.total_iob##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
	
			if intck<6 & intck>-6 & year_addition>1999 & year_addition<2015,
			absorb(fyear gvkey) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		Firm FE,Yes,Year FE,Yes,Inclusion FE,No,Cluster,Firm and Year);
	
};
};

**************************************************************************************;
* FIGURE C1: SHOCK SP INCLUSIONS - DiD - PRE and POST TRENDS for INCLUSIONS THEMSELVES; 
**************************************************************************************;
#delimit ; 
* This is for CRSP and COMP (ICODE below, because its a different sample);
foreach SIC in sich_crsp sich_comp /*icode4000*/{;

use $work\data\master_did_additions`SIC'vwk_, clear;

keep if ceo == 1;

#delimit ; 
gen ym5 = 0; replace ym5 = 1 if intck == -5;
gen ym4 = 0; replace ym4 = 1 if intck == -4;
gen ym3 = 0; replace ym3 = 1 if intck == -3;
gen ym2 = 0; replace ym2 = 1 if intck == -2;
gen ym1 = 0; replace ym1 = 1 if intck == -1;
gen ym0 = 0; replace ym0 = 1 if intck == 0;
gen yp1 = 0; replace yp1 = 1 if intck == 1;
gen yp2 = 0; replace yp2 = 1 if intck == 2;
gen yp3 = 0; replace yp3 = 1 if intck == 3;
gen yp4 = 0; replace yp4 = 1 if intck == 4;
gen yp5 = 0; replace yp5 = 1 if intck == 5;

#delimit;
set more off; 
local VARS "MHHID HHI logsale ";
local filename FigureC1;
local excel " nocons nonot excel append tstat
		keep(	ym5 ym4 ym3 ym2 ym1 ym0 
				yp1 yp2 yp3 yp4 yp5)";

foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/ {;

reghdfe `DEP' 
			ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5 
			c.hhib##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
			c.log_mefb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.volb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.leverageb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.log_tenureb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
			c.total_iob##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
	
			if intck<6 & intck>-6 & year_addition>1995 & year_addition<2015,
			absorb(fyear gvkey) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		Firm FE,Yes,Year FE,Yes,Inclusion FE,No,Cluster,Firm and Year);
	
};
};


#delimit ; 

* This is for ICODE (because its a different sample);
foreach SIC in /*sich_crsp sich_comp*/ icode4000{;

use $work\data\master_did_additions`SIC'vwk_, clear;

keep if ceo == 1;
destring gvkey, replace;

#delimit ; 
gen ym5 = 0; replace ym5 = 1 if intck == -5;
gen ym4 = 0; replace ym4 = 1 if intck == -4;
gen ym3 = 0; replace ym3 = 1 if intck == -3;
gen ym2 = 0; replace ym2 = 1 if intck == -2;
gen ym1 = 0; replace ym1 = 1 if intck == -1;
gen ym0 = 0; replace ym0 = 1 if intck == 0;
gen yp1 = 0; replace yp1 = 1 if intck == 1;
gen yp2 = 0; replace yp2 = 1 if intck == 2;
gen yp3 = 0; replace yp3 = 1 if intck == 3;
gen yp4 = 0; replace yp4 = 1 if intck == 4;
gen yp5 = 0; replace yp5 = 1 if intck == 5;

#delimit;
set more off; 
local VARS "MHHID HHI logsale ";
local filename FigureC1;
local excel " nocons nonot excel append tstat
		keep(	ym5 ym4 ym3 ym2 ym1 ym0 
				yp1 yp2 yp3 yp4 yp5)";

foreach DEP in logwpseg_allexec /*logwpsjm_allexec logwpshl_allexec*/ {;

reghdfe `DEP' 
			ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5 
			c.hhib##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
			c.log_mefb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.volb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.leverageb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)   
			c.log_tenureb##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
			c.total_iob##(ym5 ym4 ym3 ym2 ym0 yp1 yp2 yp3 yp4 yp5)  
	
			if intck<6 & intck>-6 & year_addition>1999 & year_addition<2015,
			absorb(fyear gvkey) vce(cluster gvkey fyear);
	outreg2 using `filename', `excel' addtext(Industry,`SIC',
		Firm FE,Yes,Year FE,Yes,Inclusion FE,No,Cluster,Firm and Year);
	
};
};
		
